using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Umdf.SideShow.Events;

namespace Umdf.SideShow.Scf.Events
{
    public abstract class ScfEvent : ApplicationEvent
    {
        protected const uint ScfEventSize = 8;

        private uint _previousPage;
        private uint _targetPage;

        protected ScfEvent()
        {
        }

        protected ScfEvent(Guid applicationId, Guid endpointId, int eventId, uint previousPage, uint targetPage)
            : base(applicationId, endpointId, eventId)
        {
            _previousPage = previousPage;
            _targetPage = targetPage;
        }

        public uint PreviousPage
        {
            get { return _previousPage; }
        }

        public uint TargetPage
        {
            get { return _targetPage; }
        }

        protected override int EventDataSize
        {
            get { return 8; }
        }

        protected override void WriteEventData(System.IO.Stream s)
        {
            base.WriteEventData(s);
            BinaryWriter writer = new BinaryWriter(s);
            writer.Write(_previousPage);
            writer.Write(_targetPage);
        }

        protected internal override void DeserializeObject(BinaryReader reader)
        {
            base.DeserializeObject(reader);
            _previousPage = reader.ReadUInt32();
            _targetPage = reader.ReadUInt32();
        }

        protected internal override void SerializeObject(BinaryWriter writer)
        {
            base.SerializeObject(writer);
            writer.Write(_previousPage);
            writer.Write(_targetPage);
        }
    }
}
